package com.xcn.hadoop.webhdfs;


import java.io.*;

import javax.swing.text.*;
import javax.swing.text.html.*;

public class Sample
{
	private static String text = 
	"<html>\n" +
    "<head>\n" +
    "<title>pg_0001</title>\n" +
    "\n" +
    "<style type=\"text/css\">\n" +
    ".ft3{font-style:normal;font-weight:bold;font-size:11px;font-family:Helvetica;color:#000000;}\n" +
    "</style>\n" +
    "</head>\n" +
    "<body vlink=\"#FFFFFF\" link=\"#FFFFFF\" bgcolor=\"#ffffff\">\n" +
    "\n" +
    "\n" +
    "<div style=\"position:absolute;top:597;left:252\"><nobr><span class=\"ft3\">Christina Toth, Pharm. D.</span></nobr></div>\n" +
                  "\n" +
    "\n" +
    "</body>\n" +
    "</html>";

	
	public static void main ( String args[] ) throws Exception
	{
		HTMLEditorKit htmlKit = new HTMLEditorKit ( );
		HTMLDocument htmlDoc = ( HTMLDocument ) htmlKit.createDefaultDocument ( );
		htmlKit.read ( new StringReader ( text ), htmlDoc, 0 );

		// Parse
		ElementIterator iterator = new ElementIterator ( htmlDoc );
		Element element;
		while ( (element = iterator.next ( )) != null )
		{
			AttributeSet as = element.getAttributes ( );
			Object name = as.getAttribute ( StyleConstants.NameAttribute );
			if ( name == HTML.Tag.DIV )
			{
				StringBuffer sb = new StringBuffer ( );
				int count = element.getElementCount ( );
				for ( int i = 0 ; i < count ; i++ )
				{
					Element child = element.getElement ( i );
					int startOffset = child.getStartOffset ( );
					int endOffset = child.getEndOffset ( );
					int length = endOffset - startOffset;
					sb.append ( htmlDoc.getText ( startOffset, length ) );
				}
				System.out.println ( sb );
			}
		}
	}
	
}
